﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using BizScore;

namespace ExamScore
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "excel文件 (*.xls;*.xlsx)|*.xls;*.xlsx";
            if (dialog.ShowDialog()==DialogResult.OK)
            {
                textBox1.Text = dialog.FileName;
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "excel文件 (*.xls;*.xlsx)|*.xls;*.xlsx";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                textBox2.Text = dialog.FileName;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {

            SaveFileDialog dialog = new SaveFileDialog();
            dialog.DefaultExt = "xls";
            dialog.Filter = "excel文件 (*.xls)|*.xls";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                textBox3.Text = dialog.FileName;
            }
        }

        private async void button4_Click(object sender, EventArgs e)
        {
            label4.Text = "";
            if(!File.Exists(textBox1.Text))
            {
                label4.Text = "最终岗位考试表不存在";
                return;
            }

            if (!File.Exists(textBox2.Text))
            {
                label4.Text = "分数表不存在";
                return;
            }

            button4.Enabled = false;

            DataHandle datahandle = new DataHandle();
            datahandle.SetPostInfoPath(textBox1.Text);
            datahandle.SetExamScorePath(textBox2.Text, textBox3.Text);
            label4.Text = "正在开始，请耐心等待两分钟左右";

            await Task.Run(() =>
            datahandle.HandleData()
            );


            label4.Text = "已完成";

            button4.Enabled = true;

        }
    }
}
